<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
include __ROOT__ . "../Ry/rongcloud.php";

/**
 *
 * @author yxx
 * @date 2017-10-12
 */
class Ry extends MY_Controller {
	public function __construct() {
		        parent::__construct();
		        $this->load->model('M_user');
		    }
	/**获取token
	 *@param $PID
	*/
	public function token(){
		$appKey = 'mgb7ka1nbk8dg';
		$appSecret = 'Wib8saKnAG8gJq';
		$jsonPath = "jsonsource/";
		 $userid = $this->input->get_post("userid", true);//用户id
		 $username = $this->input->get_post("username", true);//用户id
		 $uri = $this->input->get_post("uri", true);//用户id
		$RongCloud = new RongCloud($appKey,$appSecret);
		if(empty($userid)){
		       exit(json_encode(array('code'=>1,'info'=>'用户pid不能为空')));
		}
		if(empty($username)){
		       exit(json_encode(array('code'=>1,'info'=>'用户名称不能为空')));
		}
		// 获取 Token 方法
		$result = $RongCloud->user()->getToken($userid, $username, $uri);
	             $result = json_decode($result,1);
	             echo $result['token'];
	}
	public function push(){
		$appKey = 'mgb7ka1nmwj3g';
		$appSecret = 'Ej193LN5mv0P';
		$jsonPath = "../Ry/jsonsource/";
		$RongCloud = new RongCloud($appKey,$appSecret);
		// 广播消息方法（fromuserid 和 message为null即为不落地的push）
		$result = $RongCloud->push()->broadcastPush('{"platform":["ios","android"],"audience":{"userid":["1","2"]},"notification":{"alert":"this is a push"}}');
		print_r($result);
	}
}






?>
